package com.ruoyi.web.controller.registration;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.registration.domain.ResourceApply;
import com.ruoyi.registration.service.IResourceApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资源申请登记Controller
 *
 * @author Marissa
 * @date 2023-12-09
 */
@RestController
@RequestMapping("/registration/apply")
public class ResourceApplyController extends BaseController
{
    @Autowired
    private IResourceApplyService resourceApplyService;

    /**
     * 查询资源申请登记列表
     */
    @PreAuthorize("@ss.hasPermi('registration:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResourceApply resourceApply)
    {
        startPage();
        List<ResourceApply> list = resourceApplyService.selectResourceApplyList(resourceApply);
        return getDataTable(list);
    }

    /**
     * 导出资源申请登记列表
     */
    @PreAuthorize("@ss.hasPermi('registration:apply:export')")
    @Log(title = "资源申请登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResourceApply resourceApply)
    {
        List<ResourceApply> list = resourceApplyService.selectResourceApplyList(resourceApply);
        ExcelUtil<ResourceApply> util = new ExcelUtil<ResourceApply>(ResourceApply.class);
        util.exportExcel(response, list, "资源申请登记数据");
    }

    /**
     * 获取资源申请登记详细信息
     */
    @PreAuthorize("@ss.hasPermi('registration:apply:query')")
    @GetMapping(value = "/{rId}")
    public AjaxResult getInfo(@PathVariable("rId") Long rId)
    {
        return success(resourceApplyService.selectResourceApplyByRId(rId));
    }

    /**
     * 新增资源申请登记
     */
    @PreAuthorize("@ss.hasPermi('registration:apply:add')")
    @Log(title = "资源申请登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResourceApply resourceApply)
    {
        return toAjax(resourceApplyService.insertResourceApply(resourceApply));
    }

    /**
     * 修改资源申请登记
     */
    @PreAuthorize("@ss.hasPermi('registration:apply:edit')")
    @Log(title = "资源申请登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResourceApply resourceApply)
    {
        return toAjax(resourceApplyService.updateResourceApply(resourceApply));
    }

    /**
     * 删除资源申请登记
     */
    @PreAuthorize("@ss.hasPermi('registration:apply:remove')")
    @Log(title = "资源申请登记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rIds}")
    public AjaxResult remove(@PathVariable Long[] rIds)
    {
        return toAjax(resourceApplyService.deleteResourceApplyByRIds(rIds));
    }
}
